console.log("这里是4K界面优化工具！-"+window.location)

//校验某个元素是否在某个数组里
function isInArray(ele, arr) {
    let ret = false
    for (let i = 0; i < arr.length; i++) {
        if (ele==arr[i]) {
            ret = true
        }
    }
    return ret
}
//给页面添加“拓宽”按钮
function widerIt() {
    console.log('拓宽...')
    const leftColWrapperOuter = document.querySelector('#dashboard-list > div > div > div.vxe-table--render-wrapper > div.vxe-table--fixed-wrapper > div.vxe-table--fixed-left-wrapper');
    const leftColWrapperInner = document.querySelector('#dashboard-list > div > div > div.vxe-table--render-wrapper > div.vxe-table--fixed-wrapper > div.vxe-table--fixed-left-wrapper > div.vxe-table--body-wrapper.fixed-left--wrapper > table')
    let styleObj = leftColWrapperOuter.style
    styleObj.width = '370px'
    leftColWrapperOuter.setAttribute('style', styleObj.cssText)
    styleObj = leftColWrapperInner.style
    styleObj.width = '370px'
    leftColWrapperInner.setAttribute('style', styleObj.cssText)
}


function allFuncs() {
    widerIt()

    //监听左侧列宽属性变动事件
    // 创建 MutationObserver 对象
    const observer = new MutationObserver(mutations => {
      mutations.forEach(mutation => {
        // 判断是否是 width 属性的修改
        if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
          const newValue = mutation.target.getAttribute('style');
          //console.log(`width 属性值已修改为 ${newValue}`);
          let styleObj = mutation.target.style
          if (styleObj.width!='370px') {
            styleObj.width = '370px'
            mutation.target.setAttribute('style', styleObj.cssText)  
          }
        }
      });
    });
    // 将 MutationObserver 对象绑定到目标元素上，并指定需要监听的属性
    const leftColWrapperOuter = document.querySelector('#dashboard-list > div > div > div.vxe-table--render-wrapper > div.vxe-table--fixed-wrapper > div.vxe-table--fixed-left-wrapper');
    const leftColWrapperInner = document.querySelector('#dashboard-list > div > div > div.vxe-table--render-wrapper > div.vxe-table--fixed-wrapper > div.vxe-table--fixed-left-wrapper > div.vxe-table--body-wrapper.fixed-left--wrapper > table')
    observer.observe(leftColWrapperOuter, { attributes: true, attributeFilter: ['style'] });
    observer.observe(leftColWrapperInner, { attributes: true, attributeFilter: ['style'] });
}

console.log('5秒后开始执行优化界面...')
setTimeout(allFuncs, 5000)